import { computed } from 'vue';
import mxpGetSysInfoStore from '@/mxp-ui/mxp-tool/store/mxp-store-sys-info';
import { useAppStore } from '@/pinia/app';

export type ShowEvent = {
  /** 短剧标题 */
  dramaTitle: string;
  /** 支付成功的回调 */
  paySuccess: (urls: number[]) => void;
  /** 广告解锁 */
  adUnlock: () => void;
};

/** 注册基础数据 */
export function useBaseInfo() {
  const appStore = useAppStore();
  const sys = mxpGetSysInfoStore().getSysInfo();
  const loginState = computed(() => appStore.loginState);
  /** 弹出框高度 */
  const popupHeight = computed(() => Math.floor(sys.value.screenHeight * 0.8));
  /** 底部标题栏的 Bottom 偏移 */
  const titleBarBottom = computed(() => {
    const bottom = sys.value.safeAreaInsets?.bottom || 0;
    return Math.floor(bottom || 15);
  });
  /** 是否自动解锁 */
  const isAutoPay = computed(() => appStore.userInfo?.isAutoPay === 1);
  /** 视频最小高度 */
  const minVideoHeight = computed(() => Math.min(Math.ceil((sys.value.windowWidth / 9) * 16), sys.value.screenHeight));
  /** swiper高度 */
  const swiperHeight = computed(() => {
    const swH = sys.value.screenHeight - titleBarBottom.value - 40;
    if (swH - 15 >= minVideoHeight.value) {
      return swH - 15;
    } else if (swH >= minVideoHeight.value) {
      return swH;
    } else {
      return minVideoHeight.value;
    }
  });

  return {
    /** 自动解锁 */
    isAutoPay,
    /** appStore */
    appStore,
    /** 登录状态 */
    loginState,
    /** 底部标题栏的 Bottom 偏移 */
    popupHeight,
    /** 底部标题栏的 Bottom 偏移 */
    titleBarBottom,
    /** swiper高度 */
    swiperHeight,
  };
}
